package com.woniuxy.afterloan.provider;


import com.woniuxy.commons.entity.AfterLoan;
import org.apache.ibatis.jdbc.SQL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AfterLoanMapperProvider {
    private static final Logger logger = LoggerFactory.getLogger(AfterLoanMapperProvider.class);

    public String select(AfterLoan afterLoan){

        return new SQL(){
            {
                SELECT("*");
                FROM("after_loan");
                if(afterLoan.getOverdue() != null && afterLoan.getOverdue().length() != 0){
                    WHERE("overdue ='" + afterLoan.getOverdue() + "'");
                }if(afterLoan.getCollection() != null && afterLoan.getCollection().length() != 0 ){
                    WHERE("`collection` ='" + afterLoan.getCollection() + "'");
                }

            }
        }.toString();

    }

    public String update(AfterLoan afterLoan){

        return new SQL(){
            {
                UPDATE("after_loan");
                if(afterLoan.getCollection() != null && afterLoan.getCollection().length() != 0){
                    SET("collection='"+afterLoan.getCollection()+"'");
                }
                WHERE("aid=" + afterLoan.getAid());
            }
        }.toString();
    }
}
